# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: Bartłomiej Piotrowski <nospam@bpiotrowski.pl>
pkgname=luajit
_pkgname=moonjit
pkgver=2.2.0
pkgrel=2
pkgdesc="Integration fork of the original LuaJIT"
url="https://github.com/moonjit/moonjit"
arch="all"
license="MIT"
provides="lua"
subpackages="$pkgname-dev $pkgname-doc"
source="$_pkgname-$pkgver.tar.gz::https://github.com/moonjit/moonjit/archive/$pkgver.tar.gz
	10-module-paths.patch
	20-src-lib_string.patch"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	make amalg PREFIX=/usr
}

check() {
	# tests fail
	sed -i -e '/redir.lua/d' test/lib/ffi/index
	case $CARCH in
		ppc64le|s390x) sed -i -e '/math_special.lua/d' test/unportable/index;;
		armv7|armhf)
			sed -i -e '/math_special.lua/d' test/unportable/index
			sed -i -e '/bit.lua/d' test/lib/index
			;;
	esac
	make check
}

package() {
	make install DESTDIR="$pkgdir" PREFIX=/usr

	install -Dm644 COPYRIGHT \
		"$pkgdir"/usr/share/licenses/$pkgname/COPYRIGHT

	cd "$pkgdir"/usr/include && ln -s moonjit-2.2 luajit
}

sha512sums="a940dd9973801f7067e376d62ec70ab5fbf635f59c648dcb45072f55290a6752abb3b1fa307bdd81d4bf05c719338e8fbda143f62861c61cb66b34cc9e8e7d54  moonjit-2.2.0.tar.gz
9c6c410e142838c5128c70570e66beb53cc5422df5ecfb8ab0b5f362637b21ab5978c00f19bc1759165df162fd6438a2ed43e25020400011b7bb14014d87c62e  10-module-paths.patch
9d87e944580fe7a3c24e043012dbdacf5141bafb5ea83dc141c42f6641b8df117d1779c3c50ee9fccc58e625a0bc04c64dd75ab0c1815bbbf2a2e645ec0ff85e  20-src-lib_string.patch"
